<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #box{
            width: 300px;
            height: 300px;
            background-color: skyblue;
        }
    </style>
</head>
<body>
    <div id="box"></div>
<script>
    const oBox = document.getElementById("box");

    function code(e){
        console.log(1,e)
    }

    oBox.onmousemove = debounce(code,1000)
    //节流
    // function thorttle(fn,time){
    //     let lastTime = 0
    //     //事件函数
    //     return function (e){
    //       const nowTime = Date.now()
    //       if(nowTime-lastTime < time){
    //           return
    //       }
    //       lastTime = nowTime
    //       //改变this的指向
    //       fn.call(this,e)
    //     }
    // }


    //防抖
    // function  debounce(fn,time){
    //     let timer = null;
    //     return function (e){
    //         clearTimeout(timer)
    //         timer = setTimeout(()=>{
    //             fn.call(this,e)
    //         },time)
    //     }
    // }


</script>
</body>
</html>